<?php
namespace Common\Controller;
use Common\Controller\CommonController;

class GuessSongController extends CommonController
{


    /**
     * 缓存歌曲题库
     */
    public function cachequesion($time){

        $val = array();

        $val =M('SongQuersion')->field('createtime,updatetime,appid,album,sort',true)->select();
        foreach ($val as $key=>$value){

            $val[$key]['songa'] = $this->url.$val[$key]['songa'];
            $val[$key]['songb'] = $this->url.$val[$key]['songb'];
        }

        S('song_quersion',$val,$time);

    }

    /**
     *
     * 读取歌曲题库缓存并返回随机一个值
     * @return mixed
     */
    public function getcachequersion(){

        $val = S('song_quersion');

        if (!$val||$val==""){
            $this->cachequesion(3600*24*30);
            $val = S('song_quersion');
        }
        srand((float) microtime() * 10000000);
        $id = array_rand($val);

         return $val[$id];
    }

    /**
     *
     * 读取歌曲题库缓存并返回随机值
     * @return mixed
     */
    public function getmanyquersion($num=40){

        $val = S('song_quersion');

        if (!$val||$val==""){
            $this->cachequesion(3600*24*30);
            $val = S('song_quersion');
        }
        srand((float) microtime() * 10000000);
        $id = array_rand($val,$num);

        $data = array();
        for ($i=0;$i<count($id);$i++){

            $val[$id[$i]]['easy'] = 'no';
            if ($i<30){
                $val[$id[$i]]['songa'] = $val[$id[$i]]['songb'];
                $val[$id[$i]]['easy'] = 'yes';
            }

            $data[] = $val[$id[$i]];
        }

        return $data;
    }


    /**
     * 缓存礼品数据
     */
    public function setcachegift(){

        $gift = array();
        $gift = M('song_gift')->field('createtime',true)->select();

        foreach ($gift as $key=>$value){

            $gift[$key]['giftsrc'] = $this->url.$gift[$key]['giftsrc'];

        }

        S('song_gift',$gift,3600*24*30);
    }

    /**
     * 获取礼品数据
     * @return mixed
     */
    public function getcachegift(){

        $gift = S('song_gift');

        if (!$gift||$gift==""){
            $this->setcachegift();
            $gift = S('song_gift');
        }
        return $gift;
    }

    /**
     * 缓存毅力排行
     */
    public function cacherank(){

        $ranking = M('SongMember')->field('nickName,avatarUrl,number')->limit(100)->order('number desc')->select();

        S('yilirank',$ranking,600);
    }

    /**
     * 获取毅力排行
     * @return mixed
     */
    public function getcacherank(){

        $cache = S('yilirank');
        if (!$cache||empty($cache)){
            $this->cacherank();
            $cache = S('yilirank');
        }
        return $cache;

    }

    public function moni(){

        $a1 = array(
            'nickname'=>'你好时光',
            'avatarurl'=>'https://wx.qlogo.cn/mmopen/vi_32/GL4GwVXlkSMRhsvT3NNOBqRheb88xkh10xAyCdHrKibjgWZriceAPVa8WyEibiaP9sORedicVuC1Uypjmkuc9uBetJw/0',
            'score'=>'13',
        );

        $a2 = array(
            'nickname'=>'你好，生活',
            'avatarurl'=>'https://wx.qlogo.cn/mmopen/vi_32/cC0d9lAQ3SI4JJyd3YRoDyCAia4oJwwabGFF3rZDotlGZofKyfptQvcSEz5MEwo2W4AMFVlhXkHvdGiaoSK0oDJA/0',
            'score'=>'12',
        );
        $a3 = array(
            'nickname'=>'(｡･∀･)ﾉﾞ嗨你好',
            'avatarurl'=>'https://wx.qlogo.cn/mmopen/vi_32/2xbxuIEGp4VCPaZiaA86qGMn6RYfbRVRROMOgdGwl1w2T429HqqXRFdKfPdy6T4hpHdbfZxXZvicrlABUA6JkPbQ/0',
            'score'=>'10',
        );
        $a4 = array(
            'nickname'=>'生活百态',
            'avatarurl'=>'https://wx.qlogo.cn/mmopen/vi_32/BhKI1CuHnjxHRcuHK5tspzHG7nv8xQfJaKcTxfpoASfDBLQLgdAZTuIqiayDcJpndZJj2ntwibhejStHugHD9ZAw/0',
            'score'=>'10',
        );
        $a5 = array(
            'nickname'=>'asdvs',
            'avatarurl'=>'https://wx.qlogo.cn/mmopen/vi_32/0YRSb7hiaGZfYU1zVWg8QUhRnMq7twb2qZVwibs2f4jD2via98bLEcfXEYnN3j5CFRM2U1U4KlxiaiboQugU8VxoSzA/0',
            'score'=>'9',
        );
        $a6 = array(
            'nickname'=>'人生如梦',
            'avatarurl'=>'https://wx.qlogo.cn/mmopen/vi_32/gtBia22uicroVwMt22LiamAwwnvzlKggT0Nawd5X6OWrQOCOaDF8w3kngJsRNCnVODqmTuwdk4uficMG1ZiaibjjwC3Q/0',
            'score'=>'8',
        );

        $a7 = array(
            'nickname'=>'过往.....',
            'avatarurl'=>'https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTJPFdtUib2BQHfvB9hfzHKib4hUsa6b0hky1JPwT7Y8UZic4Voevnky45U9XBj4SkSofEhtRiaSoicxkPQ/0',
            'score'=>'7',
        );
        $a8 = array(
            'nickname'=>'依然记得',
            'avatarurl'=>'https://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83erYibdVmPXiblHv0z4ZPU4d9Xm3MPulWejtmhNQhiahLiaxaNJF0p4oIfBYPWXsu2zAwLqRskscC7h31A/0',
            'score'=>'6',
        );
        $a9 = array(
            'nickname'=>'流浪.......',
            'avatarurl'=>'https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTISJHoK6dDib7A7MP2dhibc7dia4V873OIwfgE285AHOv3gzlD69MF99p9Img7THqzo370GQUNsOfYcg/0',
            'score'=>'5',
        );
        $a10 = array(
            'nickname'=>'iuriik',
            'avatarurl'=>'https://wx.qlogo.cn/mmopen/vi_32/HiaasQla0F1YrAUZB7zp9giaUib9jaSEMK4icVDhdiaWx2UFBJbvHH5BAsAsQs35RbdiaX3UgTAmzUST8jjYTXWjkpOQ/0',
            'score'=>'4',
        );

        $data = array(
            '0'=>$a1,
            '1'=>$a2,
            '2'=>$a3,
            '3'=>$a4,
            '4'=>$a5,
            '5'=>$a6,
            '6'=>$a7,
            '7'=>$a8,
            '8'=>$a9,
            '9'=>$a10,
        );
        return $data;
    }

}